<?php
include('hub.php');

        class Auth {
                public function login ($username,$password){
                       
                        $koderole='';
                        $sql=mssql_query("select CAST(idUser AS TEXT) AS idUser, CAST(userLevel AS TEXT) AS userLevel from tblUser where userId='".$nama"'
						and userPwd='".$enkrip1"'");
						$data=mssql_fetch_array($sql);
                        $sql="select ID_USER, ROLE from user where NAMA_USER='".$username."' and PASSWORD='".$password."'";
                        $search=mysql_query($sql);
                        $role =mysql_fetch_array($search);
                //      print_r($role);
                        while($role){
                                $kd_user=$role['ID_USER'];
                           
                                $_SESSION['users']=$username;
                                
                                
                                if ($role['ROLE']==1){
                                        return $this->koderole="admin";
                                }
                                
                                if ($role['ROLE']==2){
                                        return $this->koderole="user";      
                                }
                                
                               
                        }
                }
                        
                public function logout(){
                        session_destroy();
                }
                
                public function __construct(){
                        session_start();
                }
        }
